/*
 * ExtensibleHash.h
 *
 *  Created on: Sep 24, 2011
 *      Author: kimi
 */

#ifndef EXTENSIBLEHASH_H_
#define EXTENSIBLEHASH_H_

#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include "BasicHashTable.h"
#include "HashRecord.h"
#include "../../Log/Log.h"
#include <sstream>

using namespace std;

class ExtensibleHash {

public:


	/**
	 *
	 */
	bool put(unsigned long key, char* data, unsigned long data_len);

	/**
	 *
	 */
	bool get(unsigned long key, char** data, unsigned long* data_len);


	/**
	 *
	 */
	bool has(unsigned long key);

	/// Funciones de LOG
	void logTableSize();
	void logHashTable();
	void logOperationWithKey(string op,unsigned long key);
	void logHashRecords();

	ExtensibleHash(string filePath,unsigned long xBlockSize);
	virtual ~ExtensibleHash();


private:

	/// update es privado
	bool getHashTableEntry(unsigned long hash, unsigned long* blockNumber,
			unsigned long* hashSize);

	/**
	 * toma los i bits menos significativos de la clave. donde i es la cantidad de bits que
	 * que utilizamos en la tabla
	 */
	unsigned long	hashFunction(unsigned long key);


	// Cantidad de bits que usa para calcular el hash
	unsigned char	bitsUsedInHash;

	// path para el hash
	string filePath;
	fstream	_file;

	BasicHashTable* hashTable;
	HashRecord*		hashRecords;
	unsigned long	blockSize;

	Log*			log;

};


#endif /* EXTENSIBLEHASH_H_ */
